// 加载fs模块
let fs = require('fs');
const { json } = require('stream/consumers');
// console.log(fs);
// 加载persons文件
let p = fs.readFileSync(__dirname+"/persons.json","utf8");
// console.log(p);
// 将Json字符串格式转换为对象格式
p = JSON.parse(p);
// console.log(p);
// 现有数据
let user = { username:"admin1",password:"12345" };

let usermsgs = p.findIndex((item) => {
    return user.username == item.username
})

if(usermsgs == -1){
    p.push(user);
    p = JSON.stringify(p);
    fs.writeFileSync(__dirname+"/persons.json",p)
    console.log("注册成功");
} else {
    console.log("用户名已被占用");
}